{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true
   },
   "source": "import numpy as np",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "arr1=np.array([1,2,3])\n",
    "print(arr1)\n",
    "print(type(arr1))\n",
    "print(f'元素类型为{arr1.dtype}')\n",
    "print(f'元素占用字节数为{arr1.itemsize}')"
   ],
   "id": "9314b4d499cbe3ec",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "arr2=np.arange(2,18,2)\n",
    "print(arr2)\n",
    "print(type(arr2))\n",
    "print(f'元素类型为{arr2.dtype}')\n",
    "print(f'元素占用字节数为{arr2.itemsize}')"
   ],
   "id": "b77b29c8b6a5c0d3",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "arr3=np.random.rand(3,4)\n",
    "print(arr3)\n",
    "print(type(arr3))\n",
    "print(f'元素类型为{arr3.dtype}')\n",
    "print(f'元素占用字节数为{arr3.itemsize}')"
   ],
   "id": "d86280af5041d9cb",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "arr4=np.random.randint(0,10,(3,3))\n",
    "print(arr4)\n",
    "print(type(arr4))\n",
    "print(f'元素类型为{arr4.dtype}')\n",
    "print(f'元素占用字节数为{arr4.itemsize}')"
   ],
   "id": "9dd926725ff9046d",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "arr5=np.random.uniform(-1,10,(3,4))\n",
    "print(arr5)\n",
    "print(type(arr5))\n",
    "print(f'元素类型为{arr5.dtype}')\n",
    "print(f'元素占用字节数为{arr5.itemsize}')"
   ],
   "id": "70dcd80844ff6ab5",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {},
   "cell_type": "code",
   "source": [
    "arr6=np.zeros((3,4),dtype=np.float64)\n",
    "print(arr6)\n",
    "print(type(arr6))\n",
    "print(f'元素类型为{arr6.dtype}')\n",
    "print(f'元素占用字节数为{arr6.itemsize}')"
   ],
   "id": "d2773390020dfc6c",
   "outputs": [],
   "execution_count": null
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-09-21T15:15:04.734707Z",
     "start_time": "2025-09-21T15:15:04.722004Z"
    }
   },
   "cell_type": "code",
   "source": [
    "arr7=arr6.astype(np.int32)\n",
    "print(arr7)\n",
    "print(type(arr7))\n",
    "print(f'元素类型为{arr7.dtype}')\n",
    "print(f'元素占用字节数为{arr7.itemsize}')"
   ],
   "id": "d218cb3bda113276",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0 0 0 0]\n",
      " [0 0 0 0]\n",
      " [0 0 0 0]]\n",
      "<class 'numpy.ndarray'>\n",
      "元素类型为int32\n",
      "元素占用字节数为4\n"
     ]
    }
   ],
   "execution_count": 11
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "260be61ec5b058e6"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
